<template>
  <!-- 放置一个图标 -->
  <div style="display:inline-block">
    <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="hFull" />
  </div>
</template>

<script>
import screenfull from 'screenfull'

export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false
    }
  },
  created() {
    screenfull.on('change', () => {
      // console.log('Am I fullscreen?', screenfull.isFullscreen ? 'Yes' : 'No')
      // 如何将这个值交给 data 中的 isFullscreen ?
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  // 计算属性可以监听到内部依赖项(data props computed)的变化
  // data props computed: 这些数据都是响应式
  // 响应式? 数据发生变化, 依赖该数据的地方都会发生更新
  // computed: {
  //   isFullscreen() {
  //     console.log(screenfull.isFullscreen)
  //     return screenfull.isFullscreen
  //   }
  // },
  methods: {
    hFull() {
      screenfull.toggle()
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
  margin-right: 15px;
}
</style>
